<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <title>编辑字典类型</title>
    <script th:replace="common/head::static"></script>
</head>
<body>
<form class="layui-form" style="padding: 20px 30px 0 0;">
    <input type="text" name="id" th:value="${sysDictionaryType.id}" th:hidden="true">
    <div class="layui-form-item">
        <label class="layui-form-label">字典名字</label>
        <div class="layui-input-block">
            <input type="text" th:value="${sysDictionaryType.name}" name="name" lay-verify="required" placeholder="请输入字典名字" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典类型</label>
        <div class="layui-input-block">
            <input type="text" th:value="${sysDictionaryType.type}" name="type" lay-verify="required" placeholder="请输入字典类型" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" th:value="${sysDictionaryType.sort}" name="sort" lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea th:text="${sysDictionaryType.remark}" name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否可用</label>
        <div class="layui-input-block">
            <input type="radio" name="valid" value="Y" title="是" th:checked="${#strings.equals(sysDictionaryType.valid, 'Y')}">
            <input type="radio" name="valid" value="N" title="否" th:checked="${#strings.equals(sysDictionaryType.valid, 'N')}">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="sysDictionaryTypeUpdate">确认</button>
            <button type="button" class="layui-btn layui-btn-primary" id="sysDictionaryTypeUpdateCancel">取消</button>
        </div>
    </div>
</form>
<script th:src="@{/common/js/common.js}"></script>
<script>
    layui.use(['form'], function () {
        const $ = layui.jquery,
            layer = layui.layer,
            form = layui.form;
        form.render();

        form.on('submit(sysDictionaryTypeUpdate)', function (obj) {
            Common.ajaxPutJSON(ctx + "/sysDictionaryType/update", JSON.stringify(obj.field), function (res){
                if (res.value === 200) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        parent.$('#sysDictionaryTypeSearchBtn').click();
                        Common.closeFrame();
                    });
                } else {
                    layer.msg(res.message, {icon: 2, time: 2000});
                }
            })
            return false;
        });

        $("#sysDictionaryTypeUpdateCancel").on('click', function () {
            Common.closeFrame();
        });
    });
</script>
</body>
</html>